package com.learning.springcloudconsumer.batch;

import com.learning.springcloudconsumer.bean.User;
import com.learning.springcloudconsumer.client.ProducerUserClient;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;

import java.util.List;

/**
 * (description)
 *
 * @author jinlong.liao on 2018/3/31
 */
public class UserBatchCommand extends HystrixCommand<List<User>> {

    private List<Integer> ids;
    private ProducerUserClient producerUserClient;

    protected UserBatchCommand(List<Integer> ids, ProducerUserClient producerUserClient) {
        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("CollapsingGroup"))
                .andCommandKey(HystrixCommandKey.Factory.asKey("CollapsingKey")));
        this.ids = ids;
        this.producerUserClient = producerUserClient;
    }

    @Override
    protected List<User> run() throws Exception {
        return producerUserClient.list(ids);
    }
}
